//
//  Prefix.h
//  guide
//
//  Created by rimi on 15/4/17.
//  Copyright (c) 2015年 yxh. All rights reserved.
//

#ifndef guide_Prefix_h
#define guide_Prefix_h


#define WIDTH [UIScreen mainScreen].bounds.size.width/375.0
//自动适应屏幕大小
//**
//* 这里的(x,y,width,hight)请填入基于375 * 667的屏幕的frame具体值
//**
#define AUTOFITSCREEN_FOR_COORDINATE(x,y,width,hight) CGRectMake(x * CGRectGetWidth([UIScreen mainScreen].bounds) / 375.0, y * CGRectGetHeight([UIScreen mainScreen].bounds) / 667.0, width * CGRectGetWidth([UIScreen mainScreen].bounds) / 375.0, hight * CGRectGetHeight([UIScreen mainScreen].bounds) / 667.0)

//自动适应屏幕大小
//**
//* 这里的(frame)请填入基于375 * 667的屏幕的frame变量名
//**
#define AUTOFITSCREEN_FOR_FRAME(frame) CGRectMake(frame.origin.x * CGRectGetWidth([UIScreen mainScreen].bounds) / 375.0, (frame.origin.y - 64) * CGRectGetHeight([UIScreen mainScreen].bounds) / 667.0 + 64, frame.size.width * CGRectGetWidth([UIScreen mainScreen].bounds) / 375.0, frame.size.height * CGRectGetHeight([UIScreen mainScreen].bounds) / 667.0)
//例外方法，不用管
#define BACKGROUNDSCREEN_FOR_FRAME(frame) CGRectMake(frame.origin.x * CGRectGetWidth([UIScreen mainScreen].bounds) / 375.0, frame.origin.y * CGRectGetHeight([UIScreen mainScreen].bounds) / 667.0, frame.size.width * CGRectGetWidth([UIScreen mainScreen].bounds) / 375.0, frame.size.height * CGRectGetHeight([UIScreen mainScreen].bounds) / 667.0)

//结合xib开发时由于不明原因造成的需要让view的属性变为frame可变
//**
//* view 你需要让其frame可变的视图
//* superview 你需要改变frame的这个视图的父视图
//**
#define ENABLEFITSCREEN(view,superview) [view removeFromSuperview];[view setTranslatesAutoresizingMaskIntoConstraints:YES];[superview addSubview:view];

//动画坐标适配-当需要写某个动画时用这个方法进行坐标或者缩放大小的适配
//**
//* width_or_x 你想要改变的目标大小的宽度或者目标位置的x坐标
//* hight_or_y 你想要改变的目标大小的高度或者目标位置的y坐标
//* 这些坐标请都填入基于 375 * 667屏幕的坐标
//**
#define TRANSFORM_SIZE_OR_POINT(width_or_x,hight_or_y) width_or_x * CGRectGetWidth([UIScreen mainScreen].bounds) / 375.0, hight_or_y * CGRectGetHeight([UIScreen mainScreen].bounds) / 667.0

/**
 *  对当前指定视图的所有子视图进行屏幕适配，开发是以375 * 667 屏幕为准，用这个方法时一定要注意，背景必须是一个imageView，不能为单纯的背景颜色
 *
 *  @param view 想要对其子视图进行匹配的视图
 *
 *  @return nil
 */
#define AUTOFITSCREEN_ALLSUBVIEWS(view) for (int i = 0; i < view.subviews.count; i++) {UIView * currentview = [[UIView alloc]init];currentview = view.subviews[i];[view.subviews[i] removeFromSuperview];[view insertSubview:currentview atIndex:i];[view.subviews[i] setTranslatesAutoresizingMaskIntoConstraints:YES];if (i != 0) {((UIView *)view.subviews[i]).frame = AUTOFITSCREEN_FOR_FRAME(((UIView *)view.subviews[i]).frame);}else{((UIView *)view.subviews[i]).frame = BACKGROUNDSCREEN_FOR_FRAME(((UIView *)view.subviews[i]).frame);}}

#endif
